package StudyCode.summary.mycollection;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ReturnsACopyOfTheArray {
	public static void main(String[] argv) {
		int[] array = new int[]{34, 35, 36, 37, 37, 37, 67, 68, 69};
		System.out.println(java.util.Arrays.toString(copy(array)));
	}

	public static int[] copy(int[] array) {
		int[] result;
		result = new int[array.length];
		System.arraycopy(array, 0, result, 0, array.length);
		return result;
	}

	public static long[] copy(long[] array) {
		long[] result;
		result = new long[array.length];
		System.arraycopy(array, 0, result, 0, array.length);
		return result;
	}


	public static float[] copy(float[] array) {
		float[] result;
		result = new float[array.length];
		System.arraycopy(array, 0, result, 0, array.length);
		return result;
	}

	public static double[] copy(double[] array) {
		double[] result;
		result = new double[array.length];
		System.arraycopy(array, 0, result, 0, array.length);
		return result;
	}

	public static double[][] copy(double[][] v) {
		double[][] ans = new double[v.length][];
		for (int k = 0; k < v.length; k++)
			ans[k] = copy(v[k]);
		return (ans);
	}

	public static int[][] copy(int[][] v) {
		int[][] ans = new int[v.length][];
		for (int k = 0; k < v.length; k++)
			ans[k] = copy(v[k]);
		return (ans);
	}


	public static String toString(double[] array) {

		StringBuffer buf = new StringBuffer(array.length);
		int i;
		for (i = 0; i < array.length - 1; i++) {
			buf.append(array[i]);
			buf.append(',');
		}
		buf.append(array[i]);
		return buf.toString();
	}

	public static String toString(double[][] array) {
		StringBuffer buf = new StringBuffer();
		for (int k = 0; k < array.length; k++) {
			buf.append(toString(array[k]));
			buf.append(System.getProperty("line.separator"));
		}
		return buf.toString();
	}


	public static String toString(int[] array) {
		StringBuffer buf = new StringBuffer(array.length);
		int i;
		for (i = 0; i < array.length - 1; i++) {
			buf.append(array[i]);
			buf.append(',');
		}
		buf.append(array[i]);
		return buf.toString();
	}


	public static String toString(int[][] array) {
		StringBuffer buf = new StringBuffer();
		for (int k = 0; k < array.length; k++) {
			buf.append(toString(array[k]));
			buf.append(System.getProperty("line.separator"));
		}
		return buf.toString();
	}
}
